Ext.ns('Ext.manager');

Ext.manager.infoPanel = Ext.extend(Ext.Panel,{
	buttonAlign:'center',
	closable : true,
	initComponent:function(){
		this.formpanel = new Ext.form.FormPanel({
			items:[{
					xtype:'textfield',
					fieldLabel : 'ID',
					id: this.id+'id',
					readOnly:true
			},{
			       		xtype:'textfield',
			       		fieldLabel:'姓名',
			       		id:this.id+'name',
			       		readOnly:true
			       	},	 
			 {
				xtype:'numberfield',
				fieldLabel:'工号',
				id:this.id+'number',
				name:'generalManager.jobnumber',
				readOnly:true
			},{
				xtype:'textfield',
				fieldLabel:'电话',
				id:this.id+'phone',
				readOnly:true
			}]
		});
		this.items  =  [this.formpanel,{
							xtype:'button',
							text:'修改资料',
							handler : function(b,e){
										var a = b.findParentBy(function(ct, cmp) { 
												return (ct instanceof Ext.manager.infoPanel) ? true : false; 
										});
										var n = contentPanel.getComponent("changemanagerinfo");
										if(n == null){
											n = new Ext.manager.infowindow({
												id:'changemanagerinfo',
												title:'修改资料',
												closable : true
											});
										}
										
										Ext.Ajax.request({
													url : "generalManager/generalManagerAction!getGeneralManagerById",
													success:function(r,o){
														var data = Ext.decode(r.responseText);
														if(data.success == false){
															Ext.Msg.alert('提示','未登录');
															return;
														}else{
															var a = data.list[0];
															n.formpanel.findById(n.id+"name").setValue(a.generalmanagername);
															n.formpanel.findById(n.id+"number").setValue(a.jobnumber);
															n.formpanel.findById(n.id+"phone").setValue(a.generalmanagerphone);
														}
										
												},
													failure:function(r,o){
														alert("failure");
												}
												});
												n.show();
										
						}
					}];
		
					Ext.manager.infoPanel.superclass.initComponent.call(this);
}
})




/***
 * window
 */
Ext.manager.infowindow = Ext.extend(Ext.Window,{
	buttonAlign:'center',
	closable : true,
	modal: true,
	initComponent:function(){
		this.formpanel = new Ext.form.FormPanel({
			items:[{
			       		xtype:'textfield',
			       		fieldLabel:'姓名',
			       		id:this.id+'name',
			       		name:"generalManager.generalmanagername"
			       	},	 
			       	{
			       		xtype:'textfield',
			       		fieldLabel:'工号',
			       		id:this.id+'number',
			       		name:'generalManager.jobnumber',
			       		blank:false
			       	},{
			       		xtype:'textfield',
			       		fieldLabel:'电话',
			       		id:this.id+'phone',
			       		name:'generalManager.generalmanagerphone'
			       	}]
		});
		this.items  = this.formpanel;
		
		this.buttons =[{
						text:'确定',
						iconCls : 'update',
						handler : function(b,e){
							var a = b.findParentBy(function(ct, cmp) { 
								return (ct instanceof Ext.manager.infowindow) ? true : false; 
							});
							
							a.formpanel.form.submit({
								waitMsg:'请等待....',
								url:'generalManager/generalManagerAction!updateGeneralManager',
								success : function(){
									Ext.Msg.alert('提示','更新信息成功');
									a.close();
									
									Ext.Ajax.request({
										url : "generalManager/generalManagerAction!getGeneralManagerById",
										success:function(r,o){
											var data = Ext.decode(r.responseText);
											if(data.success == false){
												Ext.Msg.alert('提示','未登录');
												return;
											}else{
												var a = data.list[0];
												var t = contentPanel.findById('showmanagerinfo');
												t.formpanel.findById(t.id+"id").setValue(a.generalmanagerid);
												t.formpanel.findById(t.id+"number").setValue(a.jobnumber);
												t.formpanel.findById(t.id+"name").setValue(a.generalmanagername);
												t.formpanel.findById(t.id+"phone").setValue(a.generalmanagerphone);

											}
							
									},
										failure:function(r,o){
											alert("failure");
									}
									});
									
								},
								failure : function(){
									Ext.Msg.alert('提示','更新信息失败');
									
								}
							});
							
						}
					},{
						text:'关闭',
						iconCls : 'close',
						handler : function(b,e){
							var a = b.findParentBy(function(ct, cmp) { 
								return (ct instanceof Ext.manager.infowindow) ? true : false; 
						});
							a.close();
						}
					}]
					Ext.manager.infowindow.superclass.initComponent.call(this);
}
})